package com.atguigu.gmall.task.scheduled;

import com.atguigu.gmall.common.constant.MqConst;
import com.atguigu.gmall.common.service.RabbitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author ：Shine
 * @description：
 * @date ：2021/3/8 15:46
 */
@Component
@EnableScheduling
public class ScheduledTask {
    @Autowired
    private RabbitService rabbitService;

    //    编写定时任务,分，时，日，月，周，年
    //    每隔十秒触发一次任务
    @Scheduled(cron = "0/10 * * * * ?")
    public void task() {
        System.out.println("定时任务开始启动");
        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK, MqConst.ROUTING_TASK_1, "定时任务启动");
    }

    @Scheduled(cron = "0 0 18 * * ?")
    public void clearData() {
        System.out.println("定时任务开始启动");
        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK, MqConst.ROUTING_TASK_18, "清空缓存数据，定时任务启动");
    }

}
